package com.innoking.docsys.user.service.impl;

import com.innoking.docsys.user.dao.cluster.ClusterUpmsOrganizationDao;
import com.innoking.docsys.user.dto.UpmsOrganization;
import com.innoking.docsys.user.example.UpmsOrganizationExample;
import com.innoking.docsys.user.module.UpmsOrganizationVO;
import com.innoking.docsys.user.service.UpmsOrganizationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* UpmsOrganizationService实现
* Created by shuzheng on 2017/3/20.
 *
*/
@Service
public class UpmsOrganizationServiceImpl implements UpmsOrganizationService {

    private static final Logger logger = LoggerFactory.getLogger(UpmsOrganizationServiceImpl.class);

    @Autowired
    private ClusterUpmsOrganizationDao clusterUpmsOrganizationDao;

    @Override
    public List<UpmsOrganizationVO> findOrgList() {
        List<UpmsOrganizationVO> newUpmsOrganizations = new ArrayList<>();
        List<UpmsOrganization> upmsOrganizations = clusterUpmsOrganizationDao.findOrgListDao();
        for (UpmsOrganization upmsOrganization:upmsOrganizations) {
            UpmsOrganizationVO upmsOrganizationVO = new UpmsOrganizationVO();
            BeanUtils.copyProperties(upmsOrganization,upmsOrganizationVO);
            newUpmsOrganizations.add(upmsOrganizationVO);
        }
        return newUpmsOrganizations;
    }

    @Override
    public List<UpmsOrganization> findOrgListByOrgCode(String orgCode) {
        UpmsOrganizationExample example = new UpmsOrganizationExample();
        UpmsOrganizationExample.Criteria criteria = example.createCriteria();
        criteria.andDeptCodeEqualTo(Integer.valueOf(orgCode));
        List<UpmsOrganization> upmsOrganizations = clusterUpmsOrganizationDao.selectByExample(example);
        return upmsOrganizations;
    }

    @Override
    public List<UpmsOrganization> findOrgListByOrgId(String orgId) {
        UpmsOrganizationExample example = new UpmsOrganizationExample();
        UpmsOrganizationExample.Criteria criteria = example.createCriteria();
        criteria.andOrganizationIdEqualTo(Integer.valueOf(orgId));
        List<UpmsOrganization> upmsOrganizations = clusterUpmsOrganizationDao.selectByExample(example);
        return upmsOrganizations;
    }
}